package com.neusoft.demo10;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo2 {
    public static void main(String[] args) {
        //创建一个List集合
        List<Employee> list = new ArrayList<>();
        Employee e1 = new Employee();
        e1.setName("fender");
        Employee e2 = new Employee();
        e2.setName("gibson");
        //向list集合中添加2个员工对象
        list.add(e1);
        list.add(e2);
        //遍历输出结果
        for (Employee e:list) {
            System.out.println(e.getName());
        }
        //可以使用迭代器遍历集合
        Iterator<Employee> it = list.iterator();
        while (it.hasNext()) {
            Employee employee = it.next();
            System.out.println(employee.getName());
        }
    }
}
